﻿using UnityEngine;
using System.Collections;

/// <summary>
/// Script to attach to any object that can kill the player.
/// </summary>
public class ObjectCanKillPlayer : MonoBehaviour {

	public InstantiatedSoundScript KillSound;
	StopAllPhysics physicsScript;

	// Use this for initialization
	void Start () {
		this.physicsScript = (StopAllPhysics)GameObject.Find("Scripts").GetComponent(typeof(StopAllPhysics));
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnTriggerEnter2D(Collider2D other) {
		if (other.tag == "Player") {
			if (this.tag == "Ground")
			{
				other.gameObject.rigidbody2D.isKinematic = true;
			}
			if (!this.physicsScript.GameOver)
			{
				InstantiatedSoundScript tempSound = (InstantiatedSoundScript)Instantiate(KillSound);
				tempSound.StartSound();
				this.physicsScript.GameOver = true;
				Animator anim = (Animator)GameObject.Find("MainCharacter").GetComponent(typeof(Animator));
				anim.SetTrigger("Dead");
			}
		}
	}
}
